﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    //Sensor class implemented by all device/environment sensors
    abstract class Sensor
    {
        private List<IObserver> observers = new List<IObserver>();
        protected string name;
        protected object data;
        //Add a new observer
        public void Attach(IObserver o)
        {
            observers.Add(o);
        }
        //Remove observer
        public void Detach(IObserver o)
        {
            observers.Remove(o);
        }
        //Notify all observers of a sensor's updates
        public void Notify()
        {
            foreach (IObserver o in observers)
                o.Update(name, data);
        }
        public string getName()
        {
            return name;
        }
        public object getData()
        {
            return data;
        }
    }
}
